package service;

import dao.MenuDao;
import dao.MenuDaoImpl;
import pojo.Menu;

import java.util.ArrayList;
import java.util.List;

public class MenuServiceImpl implements MenuService{
    MenuDao menuDao = new MenuDaoImpl();
    @Override
    public List<Menu> selectAll() {
        List<Menu> menuList = menuDao.selectAll();
        List<Menu> newMenuList = new ArrayList<>();//保存分级后的菜单
        for (Menu menu : menuList) {
            if (menu.getUpmenuId()==0){//说明是一级菜单
                List<Menu> secondList = new ArrayList<>();
                for (Menu menu1 : menuList) {
                    if(menu1.getUpmenuId()==menu.getMenuId()){
                        secondList.add(menu1);
                    }
                }
                menu.setSecondList(secondList);
                newMenuList.add(menu);
            }
        }
        return newMenuList;
    }
}
